import { defineStore } from 'pinia'
import { woundedListPage } from '@/utils/api/woundedfz/woundedfz'
export const useWoundedfzStore = defineStore(
  'woundedfz',
  () => {
    //伤票列表
    const List: any = []
    const woundedList = reactive({ List })
    const pageNum = ref(1) // 当前页数
    const islower = ref(false) // 是否到底部
    const TagStatus = ref('') // 标签状态
    // 获取伤票列表
    const getWoundedList = async (TagStatus: string) => {
      islower.value = true
      const res: any = await woundedListPage({
        pageNum: pageNum.value,
        pageSize: 10,
        TagStatus: TagStatus || '',
      })
      let Obj: any = res.data
      if (Obj.currPage <= Obj.totalPage) {
        pageNum.value++
        woundedList.List.push(...Obj.list)
      }
      setTimeout(() => {
        islower.value = false
      }, 500)
    }
    return {
      pageNum, // 当前页数
      islower, // 是否到底部
      woundedList, // 伤票列表
      getWoundedList, // 获取伤票列表
      TagStatus, // 状态
    }
  },
  {
    // 配置持久化
    persist: {
      // 调整为兼容多端的API
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
      paths: [],
    },
  },
)
